import 'package:flutter/material.dart';

import '../permission_model.dart';

class PermissionGroup {
  final String name;
  final int id;
  final String code;
  final String remark;
  final PermissionItem rootPermission;
  final List<PermissionItem> permissions;
  final bool isExpanded;

  PermissionGroup({
    required this.name,
    required this.id,
    required this.code,
    required this.remark,
    required this.rootPermission,
    required this.permissions,
    this.isExpanded = false,
  });
}

class PermissionItem extends ChangeNotifier {
  final int id;
  final String name;
  final String code;
  final String remark;
  final String type;
  bool _isSelected;

  bool get isSelected => _isSelected;
  
  set isSelected(bool value) {
    if (_isSelected != value) {
      _isSelected = value;
      notifyListeners();
    }
  }

  PermissionItem({
    required this.id,
    required this.name,
    required this.code,
    required this.remark,
    required this.type,
    bool isSelected = false,
  }) : _isSelected = isSelected;

  factory PermissionItem.fromPermission(Permission permission) {
    return PermissionItem(
      id: permission.id,
      name: permission.name,
      code: permission.code,
      remark: permission.remark,
      type: permission.type,
      isSelected: permission.isSelected,
    );
  }
}